package com.bicon.botu.mall.base.api;


import com.baomidou.mybatisplus.plugins.Page;
import com.bicon.botu.mall.base.common.MallHomePageConstants;
import com.bicon.botu.mall.base.dto.ChannelDto;
import com.bicon.botu.mall.base.dto.ChannelGoodsDto;
import com.bicon.botu.mall.base.service.IChannelGoodsService;
import com.bicon.botu.core.base.common.controller.BaseController;
import com.bicon.botu.core.base.common.entity.BaseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 频道商品 前端控制器
 *
 * @author 张凡
 * @date 2017/7/19 下午 14:49
 */
@RestController
@CrossOrigin
@RequestMapping("/V1.0.0/api/channelGoods")
public class ChannelGoodsApi extends BaseController {
    @Autowired
    IChannelGoodsService iChannelGoodsService;

    /**
     * 获取频道和频道商品
     *
     * @return
     */
    @RequestMapping(value = "/getChannelGoodsFromRedis", method = RequestMethod.GET)
    public BaseResult getAllChannelGoods() {
        List<ChannelDto> channelDtoList = iChannelGoodsService.getAllChannelGoods();
        return new BaseResult(MallHomePageConstants.RESPONSE_CODE_200, MallHomePageConstants.RESPONSE_MESSAGE_200, channelDtoList);
    }

    /**
     * 获取猜你喜欢频道商品
     *
     * @param pageNo
     * @param pageSize
     * @return
     */
    @RequestMapping(value = "/getGuessChannelGoods", method = RequestMethod.POST)
    public BaseResult getGuessChannelGoods(Integer pageNo, Integer pageSize) {
        Page<ChannelGoodsDto> guessGoods = iChannelGoodsService.getGuessChannelGoods(pageNo, pageSize, getUserId());
        return new BaseResult(MallHomePageConstants.RESPONSE_CODE_200, MallHomePageConstants.RESPONSE_MESSAGE_200, guessGoods);
    }

    /**
     * 获取App大首页的精选商品
     *
     * @return
     */
    @RequestMapping(value = "/getAppHomePageChannelGoods", method = RequestMethod.POST)
    public BaseResult getAppHomePageChannelGoods() {
        List<ChannelGoodsDto> channelGoodsDtoList = iChannelGoodsService.getAppHomePageChannelGoods();
        return sendResult(200, "获取成功", channelGoodsDtoList);
    }
}
